<?php
namespace app\api\Controller;
use app\common\model\Admin;  
use Firebase\JWT\JWT;

class Login extends Common
{
    
    public function Login()
    {
      $username=request()->param('username');
      $password=request()->param('password'); 
      $info=Admin::where('username',$username)->find();
      if (!$info) {
        return json(['code'=>400   ,'msg'=>'账号不存在']);
      }

      if($info['password']!=$password){
        return json(['code'=>400,'msg'=>'账号或密码错误']); 
      }
      $jwt=new JWT();
      $key = 'api123456'; 
      $payload = [
      'iss' => "http://www.api.io",
      'aud' => "http://www.api.io",
      'iat' => time(),
      'nbf' => time(),
        'aid'=>$info['id']
      ];

      $token=$jwt::encode($payload,$key);
      return json(['code'=>200,'msg'=>'登陆成功','token'=>$token]);
}
}